package com.fysports.web.event.upload;

import com.fysports.web.kit.commons.StringKit;


/**
 * Class title:  处理上传文件后逻辑  <br/>
 * Describe:     <br/>
 * 考虑到上传动作是与业务动作相关联的(如:新增新闻业务动作,需要上传新闻相关图片),
 * 只有在业务动作成功执行后,上传操作才真实生效(tmp->real),如果业务动作失败,上传动作需要回滚(tmp->delete);
 * 文件目录说明:
 * **应用在系统中有2层目录->见sysconfig.properties中设置的real和tmp目录;
 * **real和tmp目录结构完全一样,tmp目录定期清理,real目录保存业务相关文件数据
 *
 * Created by konbluesky           <br/>
 * Date : 15/12/29 下午5:14       <br/>
 * Project : weixin    <br/>
 */
public class UploadEvent {
    private String uuid;
    /*上传模块*/
    private UploadModule module;
    private TYPE type;

    /**
     * 文件上传事件
     * @param uuid
     * @param module
     * @param type  是否提交
     */
    public UploadEvent(String uuid, UploadModule module,TYPE type) {
        this.uuid = uuid;
        this.module = module;
        this.type=type;
    }


    public TYPE getType() {
        return type;
    }


    public String getUuid() {
        return uuid;
    }


    public UploadModule getModule() {
        return module;
    }


    public enum TYPE{
        MOVE,DELETE;
    }

    /**
     * 上传业务类型,预定义
     */
    public enum UploadModule{
        BRAND("brand"),
        PRODUCT("product"),
        UNKNOW("unknow");
        private String strval;
        UploadModule(String strval) {
            this.strval = strval;
        }

        public String getStr(){
            return this.strval;
        }

        public boolean equals(UploadModule ep){
            for(UploadModule e:UploadModule.values()){
                if(e.strval.equals(ep.strval)){
                    return true;
                }
            }
            return false;
        }

        public static UploadModule get(String str) {
            if(StringKit.isBlank(str)) return UNKNOW;
            for (UploadModule c : UploadModule.values()) {
                if (c.getStr().equalsIgnoreCase(str)) {
                    return c;
                }
                if(str.toLowerCase().indexOf(c.getStr().toLowerCase())>0){
                    return c;
                }
            }
            return UNKNOW;
        }


        @Override public String toString() {
            return this.getStr();
        }
    }


    public static void main(String[] args) {
        System.out.println(TYPE.MOVE==TYPE.MOVE);
    }
}
